<template>
  <div style="background: #202B61;width: 100%;height: 100%;">
    <!-- 场景设置页面 -->
    <div style=" width: 100%;background: #2E3C85;height: 8vh;float: left;position: absolute;">
      <div style="margin-top: 1.6vh;margin-left: 2vh;">
        <span style="color: #FFFF;font-size: 1.6vh;">场景：</span>
        <el-select v-model="scene" placeholder="" @change="sceneChange()" >
          <el-option
            v-for="item in sceneOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
        <span  style="right: 1%; float: right;position: absolute;">
          <el-button type="primary">上传3D图纸</el-button>
          <el-button @click="startSimulation" type="primary">开始仿真</el-button>
        </span>
      </div>

      <div style="top: 9vh;width: 100%;background: rgb(46, 60, 133);height: auto  ; float: left; position: absolute;">
        <!--路由页面-->
        <router-view :key="activeDate" @getSettingsParams='getSettingsParams'></router-view>
      </div>

    </div>
  </div>
</template>

<script>

  export default {
    name: 'sceneSettings',
    data () {
      return {
        sceneOptions: [],
        scene : "",
        settingsParams : '',
        activeDate : '',
        projectId : ''
      }
    },
    mounted : function(){

      var projectId = this.$root.project_id;

      this.projectId = projectId;

      this.$http.post("/iepsapi/fhfz/sceneSettings/initScenario?projectId="+projectId, {}).then((res) => {

          var scenarioOption = res.data;
          this.sceneOptions = scenarioOption;
          this.scene = 1;
          if(this.scene==1){
            this.$router.push({path:'/glassGreenhouseSettings',query:{"projectId":this.projectId}})
          }else{
            this.$router.push({path:'/buildingSettings',query:{"projectId":this.projectId}})
          }
      })



    },
    methods: {

      sceneChange : function(){
        /* 场景下拉切换 */
        //路由跳转
        if(this.scene==1){
          //this.$router.push('/glassGreenhouseSettings');
          this.$router.push({path:'/glassGreenhouseSettings',query:{"projectId":this.projectId}})
        }else{
          //this.$router.push('/buildingSettings');
          this.$router.push({path:'/buildingSettings',query:{"projectId":this.projectId}})
        }
      },
      getSettingsParams : function(value){
        this.settingsParams = value;
       },
      /* 开始仿真 */
      startSimulation : function () {

        var settingsParams = this.settingsParams;

        //var jsonStr = JSON.stringify(settingsParams);

        //对构建的json数据编码
        //jsonStr = encodeURIComponent(jsonStr);

        this.$http.post("/iepsapi/fhfz/sceneSettings/startSimulation?scene="+this.scene+"&projectId="+this.projectId, {settingsParams},{
          emulateJSON: true
        }).then((res) => {

          //刷新路由
          this.activeDate = new Date().getTime();

          this.$message({
            type: 'success',
            message: '下发成功'
          });

        })

      }

    }
  }
</script>

<style scoped>



</style>
